# central registry： 中央登记中心
# 1. route（url）   ==> route决定了 url 的终结点（endpoint）
# 1.1 route 还有一个重要的参数信息 叫做 options ：决定了 request 和 response 的 method方法【“GET”,"POST","etc"】,默认为GET
# 2. 视图函数： 用来处理用户的request， 并且返回（return）页面数据
# 3. 返回的数据：可以是txt文本 ，HTML文件，可以是JSON文件
from flask import Flask,request
from flask import render_template # 这个模块自动帮助我们查询

app = Flask(__name__)

@app.route('/')
def hello_world():  # put application's code here
    return render_template('hello.html') # HTML 文件

@app.route('/index')
def index():  # put application's code here
    return render_template('index.html') # HTML 文件


@app.route('/log')
def log():  # put application's code here
    return '这是日志页!'  # 文本数据

@app.route('/result',methods=['POST'])
def result():  # put application's code here
    first_name = request.form['firstname']
    last_name = request.form['lastname']
    full_name = first_name.title() + ' ' + last_name.title()
    return render_template('result.html',fullname=full_name) # HTML 文件

if __name__ == '__main__':
    app.run()

# 最终结果展示：
# FLASK_APP = app.py
# FLASK_ENV = development
# FLASK_DEBUG = 0
# In folder D:/洋洋/智超python/pycharm_projects/week-016/flask_001
# C:\ProgramData\Anaconda3\envs\flask_001\python.exe -m flask run
#  * Serving Flask app 'app.py' (lazy loading)
#  * Environment: development
#  * Debug mode: off
#  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)



#（某次失败的输出结果）：
# FLASK_ENV = development
# FLASK_DEBUG = 0
# In folder D:/洋洋/智超python/pycharm_projects/week-16/Flask_001
# D:\洋洋\智超python\pycharm_projects\week-16\Flask_001\python.exe -m flask run
#  * Serving Flask app 'app.py' (lazy loading)
#  * Environment: development
#  * Debug mode: off
#  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)    * python给的网页 hello world
# 127.0.0.1 - - [16/Dec/2021 11:02:45] "GET / HTTP/1.1" 200 -   * 请求成功
# 127.0.0.1 - - [16/Dec/2021 11:02:45] "GET /favicon.ico HTTP/1.1" 404 - * 页面资源走丢





# 原来的文件格式
# from flask import Flask
#
# app = Flask(__name__)
#
#
# @app.route('/')
# def hello_world():  # put application's code here
#     return '<h1>Hello World!</h1>'
#
#
# if __name__ == '__main__':
#     app.run()
